<?php
/**
 * Created by PhpStorm.
 * User: Mysic
 * Date: 2020/11/1
 * Time: 15:33
 */

namespace app\factory;


use app\common\library\wechat\WxPay;
use app\mocks\extend\MockWeChatPay;
use think\Env;

class PayFactory
{
    const WX_PAY = 'weChatPay';
    const ALI_PAY = 'aliPay';

    public static function instance($config = [], $type = self::WX_PAY)
    {
        if (Env::get('mock.pay')) {
            switch ($type) {
                case self::WX_PAY:
                    $payService =  MockWeChatPay::instance($config);
                    break;
                case self::ALI_PAY:
                    $payService = null;
                    break;
                default:
                    $payService =  MockWeChatPay::instance($config);
            }
            return $payService;
        }
        switch ($type) {
            case self::WX_PAY:
                $payService = new WxPay($config);
                break;
            case self::ALI_PAY:
                $payService = null;
                break;
            default:
                $payService = new WxPay($config);
        }
        return $payService;
    }
}